home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wb613_01.zip / WN_GDOUB.C < prev    next >
C/C++ Source or Header  |  1991-03-15  |  7KB  |  157 lines

  1. /*
  2. ** The Window BOSS's Data Clerk
  3. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  4. ** All rights reserved.
  5. **
  6. ** wn_gdoubl - get double from window with validation 
  7. **
  8. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  9. ** All rights reserved.
  10. **
  11. */
  12.  
  13. #include "winboss.h"                    /* standard stuff */
  14.  
  15. /*
  16. **************
  17. * wn_gdouble *
  18. **************
  19. */
  20.  
  21. /*
  22. ** wn_gdouble(fun,frm,fld,wn,row,col,prmpt,atrib,fill,v,fwidth,ndec,low,high,ubuff,hlpmsg,errmsg)
  23. **
  24. **    int        fun - fucntion code (SET || XEQ)
  25. **    (WIFORM)   frm - form pointer  (actual || NFRM)
  26. **    int        fld - field # in form (actual || NFLD)
  27. **    (WINDOWPTR) wn - window pointer
  28. **    int        row - row in window where data input begins
  29. **    int        col - col in window where data input begins
  30. **    (char *) prmpt - field promt (call with NSTR for none)
  31. **    unsigned atrib - field (not prompt) atributes 
  32. **    char      fill - field fill character
  33. **    (double  *)  v - pointer to double for return value (low-high)
  34. **    int     fwidth - width of mask (maximum # of digits is 20 with sign)
  35. **    int       ndec - # of decimal places 
  36. **    double     low - minimum value (lower limit of value)
  37. **    double    high - maximum value (upper limit of value)
  38. **    (char *) ubuff - pointer to char array of fwidth+2 bytes for editing 
  39. **    (char *)hlpmsg - pointer to help message (call with NSTR for none)
  40. **    (char *)errmsg - pointer to err message (call with NSTR) for none)
  41. **
  42. ** RETURNS:
  43. **
  44. **    V via pointer.
  45. **
  46. **    NULL if error, else the non zero value returned from wn_input.
  47. **
  48. ** NOTES:
  49. **
  50. **  FUN -   fun can only be SET for form setup, or XEQ for immediate
  51. **          execution.  When called with SET, valid arguements for both
  52. **          "frm" and "fld" must be specfied.  frm is the field pointer
  53. **          returned from frmopn(), and fld is the field sequence number
  54. **          in the form for this field.  When called with XEQ frm must
  55. **          be NFRM and fld must NFLD.
  56. **
  57. **  UBUFF - Editing buffer.  Must be of sufficent size to hold the
  58. **          data as it is entered.  Typical value is the length
  59. **          of the mask + 2 bytes (strlen(mask)+2).
  60. **
  61. **          On entry, the first byte of ubuff should be 
  62. **          a null, otherwise wn_input assumes there is valid
  63. **          data there and will enter edit mode.  This can be 
  64. **          handy if there is a need for prefilled but editable
  65. **          fields.  In actual pratice, wn_input uses this
  66. **          buffer for both initial character data entry and
  67. **          subsequent editing.
  68. **
  69. **          On return, ubuff contains the actual data entered in
  70. **          character format with fill and mask characters as
  71. **          spaces (e.g. "-1240.20").
  72. **
  73. **  Calls wn_input to perform data entry.
  74. **
  75. **  Data must satisfy validation checks for function to return.
  76. **
  77. **  Calls wn_iemsg(errmsg) when vaildation fails.
  78. */
  79.  
  80. /*
  81. **************
  82. * wn_gdouble *
  83. **************
  84. */
  85.  
  86. wn_gdouble(fun,frm,fld,wn,row,col,prmpt,atrib,fill,value,fwidth,ndec,low,high,ubuff,hlpmsg,errmsg)
  87. int fun;                                /* SET or XEQ */
  88. WIFORM frm;                             /* form pointer or NFRM */
  89. int fld;                                /* field number or NFLD */
  90. WINDOWPTR wn;                           /* window to use */
  91. int row, col;                           /* position of input field */
  92. char *prmpt;                            /* prompt string */
  93. unsigned atrib;                         /* data entry atribute */
  94. char fill;                              /* fill char */
  95. double *value;                          /* the double */
  96. double low, high;                       /* limits: low & high */
  97. int fwidth;                             /* field width */
  98. int ndec;                               /* # of decimal places */
  99. char *ubuff;                            /* returns "value" */
  100. char *hlpmsg, *errmsg;                  /* help and error messages */
  101. {
  102. double v;                               /* temp value */
  103. char mask[25];                          /* long precision */
  104. unsigned r;                             /* sscanf return value */
  105. int rv;                                 /* return value */
  106.  
  107.   if(fun != SET && fun != XEQ)          /* saftey check */
  108.     return(NULL);
  109.  
  110.   if(fun == SET) {                      /* set up */
  111.     if(frm[fld]->pself != (char *)frm[fld])
  112.       wns_ierr("wn_gfloat");            /* die if memory is mangled */
  113.     frm[fld]->wn = wn;                  /* set window */
  114.     frm[fld]->row = row;                /* set row */
  115.     frm[fld]->col = col;                /* set col */
  116.     frm[fld]->prmpt = prmpt;            /* set prompt */
  117.     frm[fld]->atrib = atrib;            /* set attribute */
  118.     frm[fld]->fill = fill;              /* set fill character */
  119.     frm[fld]->fcode = GDOUBL;           /* function code */
  120.     frm[fld]->v1.vdp = value;           /* &value */
  121.     frm[fld]->v2.vi = fwidth;           /* fwidth */
  122.     frm[fld]->v3.vi = ndec;             /* # of decimal places */
  123.     frm[fld]->v4.vd = low;              /* lower limit */
  124.     frm[fld]->v5.vd = high;             /* upper limit */
  125.     frm[fld]->v6.vcp = ubuff;           /* &ubuff */
  126.     frm[fld]->v7.vcp = hlpmsg;          /* &hlpmsg */
  127.     frm[fld]->v8.vcp = errmsg;          /* &errmsg */
  128.     return(TRUE);
  129.   }
  130.  
  131.   strcpy(mask,"FFFFFFFFFFFFFFFFFFFFF"); /* set mask */
  132.   if(fwidth > 20 || ndec > fwidth) {    /* dont allow foolishness */
  133.     *ubuff = NUL;                       /* indicate error */
  134.     return(NULL);                       /* and return */
  135.   }
  136.   mask[fwidth] = NUL;                   /* set length */
  137.   fwidth = fwidth - (ndec+1);           /* decimal position */
  138.   mask[fwidth] = '.';                   /* set decimal point */
  139. begin:
  140.   if(!(rv=wn_input(wn,row,col,prmpt,mask,fill,atrib,ubuff,hlpmsg))) {
  141.     *ubuff = NUL;                       /* indicate error */
  142.     return(NULL);                       /* indicate error */
  143.   }
  144.   if(wni_frmflg) return(TRUE);          /* wn_frmget in progress */
  145.   if(wns_escape) return(rv);            /* escape pressed ?? */
  146.   r = sscanf(ubuff, "%lf", &v);         /* convert to float */
  147.   if(r == EOF || r == 0) v = 0.0;       /* no data! */
  148.   if(v < low || v > high) {             /* bad float */
  149.     wn_iemsg(errmsg);                   /* do error message */
  150.     goto begin;                         /* and stgart over */
  151.   }
  152.   *value = v;                           /* load user value */
  153.   return(rv);                           /* all is well.. in gross sense */
  154. }
  155.  
  156. /* End */
  157.